<?php

require_once("lib/autoload.php");

#header('Content-type: application/json');

extract($_GET);
if (isset($id)) {
    $dc = new DataController();
    $dc->connect();
    $petition = $dc->getPetition($id);    
    
    if ($petition != NULL) {
        if (isset($user)) {
            print json_encode(array("success"=>true,
                                    "signed"=>$dc->isPetitionSignedByUser($id, $user),
                                    "petition"=>$petition->getJsonArray()));                
        }
        else {
            print json_encode(array("success"=>true,
                                    "petition"=>$petition->getJsonArray()));
        }        
    }
    else {
        print "{success: 'false'}";
    }
    $dc->disconnect();
}
else {
    print "{success: 'false'}";
}


?>